package com.sikaryofficial.backend.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author : qinjinyuan
 * @desc : 礼品兑换业务类型类型枚举
 * @date : 2023/11/04 10:08
 */
@Getter
@AllArgsConstructor
public enum PrizeRedeemBusinessTypeEnum {
    /**
     * 积分兑换
     */
    REDEEM(1,  "Redeem Points"),
    /**
     * 大转盘
     */
    LOTTERY_TURNTABLE(2, "Wheel of fortune"),

    /**
     * 刮刮乐
     */
    LOTTERY_SCRATCH(3, "Scratch card"),

    /**
     * 积分预约0元定时抢购
     */
    POINTS_RESERVATION(4, "Points reservation timed flash sale");

    private final Integer code;
    private final String name;

    public static PrizeRedeemBusinessTypeEnum getByCode(Integer code) {
        return Arrays.stream(PrizeRedeemBusinessTypeEnum.values())
                .filter(pointRuleEnum -> Objects.nonNull(code) && pointRuleEnum.getCode().equals(code))
                .findFirst().orElse(null);

    }

    public static String getNameByCode(Integer code) {
        PrizeRedeemBusinessTypeEnum prizeTypeEnum = getByCode(code);
        if (Objects.isNull(prizeTypeEnum)) {
            return "";
        }
        return prizeTypeEnum.getName();
    }

}
